package com.ZeroCarbon.domain.dto;

import cn.hutool.core.bean.BeanUtil;
import com.ZeroCarbon.domain.po.QuestionInfo;
import com.ZeroCarbon.utils.JsonUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * 密保问题类
 *
 * @since 2024-10-13
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class QuestionInfoDTO {

    /**
     * 账号
     */
    @TableId(type = IdType.INPUT)
    private String id;

    /**
     * 密保问题
     */
    @TableField(exist = false)
    private Map<String, String> questions;

    /**
     * QuestionInfoDTO转PO
     */
    public QuestionInfo toQuestionInfo() {
        //转化对象
        QuestionInfo questionInfo = BeanUtil.copyProperties(this, QuestionInfo.class);
        //设置信息
        return questionInfo.setQuestionJson(JsonUtils.ObjectToJson(questionInfo));
    }
}
